//
//  WHListDetailTableViewCell.m
//  GroupFourFM
//
//  Created by dllo on 15/12/25.
//  Copyright © 2015年 GroupFour. All rights reserved.
//

#import "WHListDetailTableViewCell.h"

@implementation WHListDetailTableViewCell

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        [self createCell];
    }
    
    return self;
}

-(void)createCell
{
    //排名
    self.numLabel = [[UILabel alloc] init];
    self.numLabel.backgroundColor = CLEAR;
    self.numLabel.font = [UIFont systemFontOfSize:20 weight:0.05];
    [self.contentView addSubview:self.numLabel];
    self.numLabel.textAlignment = NSTextAlignmentCenter;
    self.numLabel.textColor = [UIColor lightGrayColor];

    [self.numLabel mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.mas_equalTo(@5);
        make.centerY.equalTo(self.contentView.mas_centerY);
        make.width.mas_equalTo(@30);
        make.height.mas_equalTo(@20);
    }];
    
    //图片
    self.newsPic = [[UIImageView alloc] init];
    self.newsPic.backgroundColor = CLEAR;
    [self.contentView addSubview:self.newsPic];
    
    [self.newsPic mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.equalTo(self.numLabel.mas_right).offset(5);
        make.top.mas_equalTo(@10);
        make.bottom.mas_equalTo(@-10);
        make.width.equalTo(self.contentView.mas_height).offset(-20);

    }];
    
    //标题
    self.newsTitle = [[UILabel alloc] init];
    self.newsTitle.backgroundColor = CLEAR;
    self.newsTitle.font = [UIFont systemFontOfSize:15 weight:0];
    [self.contentView addSubview:self.newsTitle];
    
    [self.newsTitle mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.equalTo(self.newsPic.mas_right).offset(10);
        make.top.equalTo(self.newsPic);
        make.right.mas_equalTo(@-40);
        make.height.mas_equalTo(@(SCREEN_HEIGHT*0.03));
        
    }];
    
    //副标题
    self.newsDigest = [[UILabel alloc] init];
    self.newsDigest.backgroundColor = CLEAR;
    self.newsDigest.font = [UIFont systemFontOfSize:13 weight:0];
    [self.contentView addSubview:self.newsDigest];
    self.newsDigest.textColor = [UIColor lightGrayColor];
    self.newsDigest.numberOfLines = 3;
    
    [self.newsDigest mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.right.equalTo(self.newsTitle);
        make.centerY.equalTo(self.contentView.mas_centerY);
        make.height.mas_equalTo(@20);
        
    }];
    
    UIView *lineView = [[UIView alloc] init];
    lineView.backgroundColor = [UIColor lightGrayColor];
    [self.contentView addSubview:lineView];
    
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.equalTo(self.newsPic.mas_right);
        make.right.mas_equalTo(@0);
        make.top.equalTo(self.contentView.mas_bottom);
        make.height.mas_equalTo(@0.5);
        
    }];
    
    self.iconImageV = [[UIImageView alloc] init];
    _iconImageV.image = [UIImage imageNamed:@"findcell_arrow"];
    [self.contentView addSubview:self.iconImageV];
    
    [self.iconImageV mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.right.mas_equalTo(@(-20));
        make.centerY.equalTo(self.contentView.mas_centerY);
        make.height.mas_equalTo(@15);
        make.width.mas_equalTo(@10);
        
    }];
    //集数前图标
    self.iconImage = [[UIImageView alloc] init];
    _iconImage.backgroundColor = CLEAR;
    
    [self.contentView addSubview:self.iconImage];
    
    [self.iconImage mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.equalTo(self.newsPic.mas_right).offset(10);
        make.bottom.mas_equalTo(@-10);
        make.height.width.mas_equalTo(@15);
    }];
    
    //集数
    self.tracksLable = [UILabel new];
    [self.contentView addSubview:self.tracksLable];
    self.tracksLable.font = [UIFont systemFontOfSize:13 weight:0];
    self.tracksLable.textColor = [UIColor lightGrayColor];
    [self.tracksLable mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.equalTo(self.iconImage.mas_right).offset(5);
        make.bottom.height.equalTo(self.iconImage);
        make.width.mas_equalTo(@100);
        
    }];
    
}

-(void)setAlbumModel:(WSAlbumModel *)albumModel
{
    if (_albumModel != albumModel) {
        _albumModel = albumModel;
    }
    
    NSURL *url = [NSURL URLWithString:albumModel.albumCoverUrl290];
    [self.newsPic sd_setImageWithURL:url placeholderImage:PLACEHOLDER_CELL_SAME];
    self.newsTitle.text = albumModel.title;
    self.newsDigest.text = albumModel.intro;
    [self.newsDigest sizeToFit];
    self.iconImage.image = [UIImage imageNamed:@"album_tracks@2x.png"];
    self.tracksLable.text = [NSString stringWithFormat:@"%@集",albumModel.tracksCounts];
    
}

-(void)setTrackModel:(WSTrackModel *)trackModel{
    
    if (_trackModel != trackModel) {
        
        _trackModel = trackModel;
    }
    NSURL *url = [NSURL URLWithString:trackModel.coverSmall];
    [self.newsPic sd_setImageWithURL:url placeholderImage:PLACEHOLDER_CELL_SAME];
    //变圆形
    self.newsPic.layer.masksToBounds = YES;
    self.newsPic.layer.cornerRadius = (SCREEN_HEIGHT*0.16-20)/2;
    self.newsTitle.text = trackModel.title;
    [self.newsTitle sizeToFit];
    self.newsDigest.text = [NSString stringWithFormat:@"by %@", trackModel.nickname];
    [self.newsTitle mas_updateConstraints:^(MASConstraintMaker *make) {
      
       make.left.equalTo(self.newsPic.mas_right).offset(10);
       make.top.equalTo(self.newsPic);
       make.right.mas_equalTo(@-40);
       make.height.mas_equalTo(@(SCREEN_HEIGHT*0.06));
       
    }];
    self.newsTitle.numberOfLines = 2;
    self.iconImageV.hidden = YES;
    //更新
    [self.newsDigest mas_updateConstraints:^(MASConstraintMaker *make) {
       
        make.left.right.equalTo(self.newsTitle);
        make.centerY.equalTo(self.contentView.mas_centerY).offset(20);
        make.height.mas_equalTo(@20);

        
    }];
    
}

-(void)setAuthorModel:(WSAuthorModel *)authorModel{
    
    if (_authorModel != authorModel) {
        
        _authorModel = authorModel;
    }
    
    NSURL *url = [NSURL URLWithString:authorModel.middleLogo];
    [self.newsPic sd_setImageWithURL:url placeholderImage:PLACEHOLDER_CELL_SAME];
    self.newsTitle.text = authorModel.nickname;
    self.newsDigest.text = authorModel.personDescribe;
    self.iconImage.image = [UIImage imageNamed:@"user_fans"];
    self.tracksLable.text = [NSString stringWithFormat:@"%.2f万", (CGFloat)authorModel.followersCounts/10000];
    [self.tracksLable sizeToFit];
    
}

@end
